<template>
 <div class="borrower">

    <el-card class="box-card" shadow="never" style="border:0px;">
      <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="tableData" size="small" element-loading-text="正在查询中。。。" :header-cell-style="{background:'#F7F7F8',color:'#606266'}" fit highlight-current-row>


      <el-table-column align="center" label="文件名称" prop="fileTypeName">
        <template slot-scope="scope">
          <span v-if="handleFileType(scope.row)">{{scope.row.fileTypeName.replace("*","")}}<span style="color:red">*</span></span>
          <span v-else>{{scope.row.fileTypeName}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="文件数量" prop="fileNum"/>
      <el-table-column align="center" label="上传时间" prop="createTime"/>
      <el-table-column align="center" label="角色" prop="position"/>
      <el-table-column align="center" label="操作人" prop="createName"/>

      <el-table-column align="center" label="操作" width="300" class-name="small-padding fixed-width">
        <template slot-scope="scope"><!-- v-if="handleShowFlag(scope.row)"-->
          <el-button  type="primary" size="mini" v-if="handleShowFlag(scope.row)"
           @click="uploadFile(scope.row)">上传{{getUploadName(scope.row.fileType)}}</el-button>
          <el-button v-if="scope.row.fileNum>0"  type="primary" size="mini" @click="lookFile(scope.row)">查看{{getUploadName(scope.row.fileType)}}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-row type="flex" class="row-bg" justify="center" style="margin-top:50px;">
      <el-col :span="10" v-if=" changeValue != 'detail'">
         <el-button  type="primary" @click="backStep" style="width:150px;height:40px;">上一步</el-button>
        <el-button  type="warning" @click="createData" style="width:150px;height:40px;">预览</el-button>
      </el-col> 
      <el-col v-else>
        <el-button v-permission="'system:project-file:batch'" :loading="loading" type="primary" @click="exportData" style="width:150px;height:40px;display:block;margin:0 auto;">批量下载</el-button>
      </el-col>
    </el-row>


    <!-- 添加或修改对话框 -->
    <el-dialog :title="dialogStatusTitle" :visible.sync="dialogFormVisible" :close-on-click-modal="false" >
      <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="100px" style="width: 90%; margin-left:50px;">
          <el-form-item v-if="dataForm.fileType === 12" label="第三方姓名" prop="thirdName" :rules="{required: true,message: '请输入第三方姓名',trigger: 'blur'}">
          <el-input  v-model="dataForm.thirdName" placeholder="请输入第三方姓名"/>
        </el-form-item>
          <el-form-item v-if="dataForm.fileType === 12"  label="银行卡号" prop="bankNo" :rules="[{required: true,message: '请输入银行卡号',trigger: 'blur'},
          { required: true, min:16,max:19, message: '请输入正确的银行卡号码', trigger: ['blur'] }]">
          <el-input v-model="dataForm.bankNo" placeholder="请输入银行卡号"/>
        </el-form-item>
          <el-form-item v-if="dataForm.fileType === 12"  label="开户行" prop="openBank" :rules="{required: true,message: '请输入开户行',trigger: 'blur'}">
          <el-input v-model="dataForm.openBank" placeholder="请输入开户行"/>
        </el-form-item>
        <!--:headers="headers"-->
         <el-form-item v-if="dataForm.fileType == 24" label="录音列表" prop="fileUrlList">
           <el-upload
             class="upload-demo"
             drag
            :action="uploadPath"
            :file-list="galleryFileList"
            :headers="headers"
            :before-upload="handleBeforeUpload"
            :on-error="handleUploadError"
            :on-success="handleGalleryUrl"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove"
            multiple
            accept=".mp3,.wav,.aiff,.pcm,.wma,.ogg,.aac">
           <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip">只能上传.mp3,.wav,.aiff,.pcm,.wma,.ogg,.aac文件</div>
          </el-upload>
        </el-form-item>
         <el-form-item v-else-if="dataForm.fileType == 22 || dataForm.fileType == 23" label="视频列表" prop="fileUrlList">
           <el-upload
             class="upload-demo"
             drag
            :action="uploadPath"
            :file-list="galleryFileList"
            :headers="headers"
            :before-upload="handleBeforeUpload"
            :on-error="handleUploadError"
            :on-success="handleGalleryUrl"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove"
            multiple
            accept=".mp4,.mov,.wmv,.flv,.avi,.mkv,.avchd,.webm">
           <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip">只能上传.mp4,.mov,.wmv,.flv,.avi,.mkv,.avchd,.webm文件</div>
          </el-upload>
        </el-form-item>
         <el-form-item v-else label="文件列表" prop="fileUrlList">
           <!-- <el-upload
            :action="uploadPath"
            :file-list="galleryFileList"
            :headers="headers"
            :on-success="handleGalleryUrl"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove"
            multiple
            accept=".jpg,.jpeg,.png,.gif"
            list-type="picture-card">
            <i  class="el-icon-plus"/>
            <div  slot="tip" class="el-upload__tip">只能上传.jpg,.jpeg,.png,.gif文件</div>
          </el-upload> -->
          <el-upload
          style="margin-top:30px;"
          class="upload-demo"
          drag
          :action="uploadPath"
          :file-list="galleryFileList"
          :headers="headers"
          :before-upload="handleBeforeUpload"
          :on-error="handleUploadError"
          :on-success="handleGalleryUrl"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove"
          :on-exceed="handleUploadLimit"
          accept=".jpg,.jpeg,.png,.gif,.pdf"
          multiple>
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <!-- <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div> -->
        </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small"  @click="dialogFormVisible = false">取消</el-button>
        <!-- <el-button size="mini" v-if="dialogStatus=='create'" type="primary" @click="createData">确定</el-button> -->
        <el-button type="primary" size="small" @click="updateData">确定上传</el-button>
      </div>
    </el-dialog>

        <!-- 添加或修改对话框  v-if="dataForm.fileType === 12"-->
    <el-dialog :title="dialogStatusPic" :visible.sync="dialogFormVisibleDetail" :close-on-click-modal="false" >
      <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="100px" style="width: 80%; margin-left:50px;">
          <el-form-item v-if="dataForm.fileType === 12"  label="第三方姓名" prop="thirdName">
         <span>{{dataForm.thirdName}}</span>
        </el-form-item>
          <el-form-item  v-if="dataForm.fileType === 12" label="银行卡号" prop="bankNo">
           <span>{{dataForm.bankNo}}</span>
        </el-form-item>
          <el-form-item v-if="dataForm.fileType === 12" label="开户行" prop="openBank">
           <span>{{dataForm.openBank}}</span>
        </el-form-item>
        <!--:headers="headers"-->
        <el-form-item v-if="dataForm.fileType == 24" label="录音列表" prop="fileUrlList">
          <audio v-for="(item,index) in dataForm.fileUrlList" :key="index" :src="item.fileUrl" controls="controls"></audio>
        </el-form-item>
        <el-form-item v-else-if="dataForm.fileType == 22 || dataForm.fileType == 23 " label="视频列表" prop="fileUrlList">
          <video
            v-for="(item,index) in dataForm.fileUrlList"
            :src="item.fileUrl"
            :key="index"
            controls
            width="100%"
            height="100%"
        ></video>
        </el-form-item>
         <el-form-item v-if="dataForm.fileType != 24 && dataForm.fileType != 22 && dataForm.fileType != 23" label="缩略图" prop="fileUrlList">
            <el-image
            draggable="true"
            class="list-item"
            v-for="(item,index) in dataForm.fileUrlList"
            @dragover="allowDrop" 
            @dragstart="dragStart($event, index)"
            @drop="drop($event, index)"
            v-if="handleShowFileType(item.fileUrl)"
            style="width: 100px; height: 100px"
            :src="item.fileUrl"
             fit="contain"
             v-bind:key="item.id"
            :preview-src-list="previewPicUrlList">
          </el-image>
        </el-form-item>
        <el-form-item v-if="dataForm.fileType != 24 && dataForm.fileType != 22 && dataForm.fileType != 23" label="PDF" prop="fileUrlList">
           <div v-for="(item,index) in dataForm.fileUrlList" :key="index">
            <el-link v-if="!handleShowFileType(item.fileUrl)" type="primary" @click="handlePreviewPdf(item.fileUrl)">{{item.fileName}}</el-link>
           </div>
        </el-form-item>
      </el-form>
      
      <div slot="footer" class="dialog-footer">
        <el-button size="small"  @click="dialogFormVisibleDetail = false">取消</el-button>
        <!-- <el-button size="mini" v-if="dialogStatus=='create'" type="primary" @click="createData">确定</el-button> -->
        <el-button type="primary" size="small" @click="createDataFile">保存拖动</el-button>
      </div>
    </el-dialog>

    <el-dialog title="预览" :visible.sync="dialogFormVisiblePic" :close-on-click-modal="false">
      <img  v-if="handleShowFileType(dialogImageUrl)" width="100%" :src="dialogImageUrl" alt="">
      <!-- <el-link v-else type="primary" @click="handlePreviewPdf(dialogImageUrl)">预览PDF</el-link> -->
      <iframe :src="dialogImageUrl"  width="100%" height="600px"></iframe>
    </el-dialog>
    </el-card>
    <el-dialog
      title="批量下载进度"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :show-close="false"
      width="30%"
      top="300px"
      >
        <el-progress :percentage="percentage" :color="customColor"></el-progress>
    </el-dialog>
  </div>
</template>

<style>
  .demo-image__preview{
    width: 100px;
    height: 100px;
    margin:0 auto;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #20a0ff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px;
    text-align: center;
  }
  .avatar {
    width: 145px;
    height: 145px;
    display: block;
  }
</style>

<script>
import { mapGetters } from 'vuex';
import { getToken } from '@/utils/auth'
import { listFileByProjecId,createProjectFile,deleteProjectFile
,uploadPath,exportFile } from '@/api/projectFile'
import { taskSupplementStatus } from '@/api/project'
import pdf from 'vue-pdf'
export default {
  name: 'file',
  components: { pdf },
  // 接受父组件的值
  props: {
     changeValue: undefined,
     projectId: undefined,
     projectStatus: undefined,
     operationLook: undefined,
     taskId: undefined,
      realName:undefined
    },
  data() {
    return {
      uploadPath,
      defaultProjectId: undefined,
      appointNextTime:undefined,
      updateParam: undefined,
      list: undefined,
      total: 0,
      listLoading: false,
      options:[],
      picUrlList:[
      ],
      previewPicUrlList:[
      ],
      value:undefined,
      galleryFileList:[],
      beforeArr:[],
      dialogImageUrl: undefined,
      descriptions: ["客户经理"],
      projectStatusName: "客户经理",
      projectStatusName1: "审查岗",
      listQuery: {
        page: 1,
        limit: 20,
        pid: undefined,
        categoryName: undefined,
        sort: 'add_time',
        order: 'desc'
      },
      dataForm: {
        fileTypeName: undefined,
        fileNum: undefined,
        createTime: undefined,
        description:undefined,
        createName:undefined,
        picUrl: undefined
      },
      dialogFormVisible: false,
      dialogFormVisiblePic: false,
      dialogStatus: 'create',
      dialogStatusPic:'',
      dialogStatusTitle: undefined,
      dialogFormVisibleDetail: false,
      data: [{
      }],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      textMap: {
        update: '编辑',
        create: '创建'
      },
      rules: {
        name: [
          { required: true, message: '姓名', trigger: 'blur' }
        ]
      },
      downloadLoading: false,
      tableData: [],
      loading:false,
      dialogVisible:false,
      percentage:0,
      customColor: '#409eff',
    }
  },
  computed: {
    ...mapGetters(['roles']),
    headers() {
      return {
        'Authorization': "Bearer-"+getToken()
      }
    }
  },
  created() {
    //如果是补资料状态 查询补资料上一节点状态1
    if( this.projectStatus == 18){
      this.taskSupplementStatus()
    }
    console.log(this.roles)
    if( this.projectId === undefined ) {
      this.defaultProjectId = localStorage.getItem("projectId")
    }else{
      this.defaultProjectId = this.projectId
    }
    if( this.projectStatus >= 20 ) {
      this.descriptions.push("尽职调查岗")
    }
    if( this.projectStatus >= 26 ) {
      this.descriptions.push("尽职调查岗")
      this.descriptions.push("待公证")
    }
    if( this.projectStatus >= 27 ) {
      this.descriptions.push("办押岗")
    }

    this.getFileList()
  },
  methods: {
        //取消默认行为
        allowDrop(e){
            e.preventDefault();
        },
        //开始拖动
        dragStart(e, index){
            let tar = e.target;
            e.dataTransfer.setData('Text', index);
            if (tar.tagName.toLowerCase() == 'li') {
                // console.log('drag start')
                // console.log('drag Index: ' + index)
            }
        },
        //放置
        drop(e, index){
            var temp;
            var temp1;
            this.allowDrop(e);
            console.log(this.dataForm.fileIdList)
            // console.log('drop index: ' + index);
            //使用一个新数组重新排序后赋给原变量
            
            let arr1 = this.dataForm.fileIdList.concat([]);
            let arr = this.dataForm.fileUrlList.concat([]),
                dragIndex = e.dataTransfer.getData('Text');
                temp = arr.splice(dragIndex, 1);
                temp1 = arr1.splice(dragIndex, 1);

            arr.splice(index, 0, temp[0]);
            arr1.splice(index, 0, temp1[0]);
            // console.log('sort');

            console.log(arr1)
            this.dataForm.fileUrlList = arr;
            this.dataForm.fileIdList = arr1;
            this.$notify.success("图片位置拖动成功")

        },
      handlePreviewPdf(item){
        this.dialogImageUrl = item
        this.dialogFormVisiblePic = true
      },
      handleShowFileType(item){
        if( item!=undefined &&  item.indexOf("pdf")==-1){
          return true
        }
        return false
      },
      handleShowFlag(row) {
        if(this.operationLook) {
          return false
        }
      if(this.roles.indexOf("业务负责人")!=-1){
          return true
        }
        // return true
        if(this.roles.indexOf("admin")!=-1 || this.roles.indexOf("超级管理员")!=-1 
        || this.roles.indexOf("团队长")!=-1 || this.roles.indexOf("部长")!=-1 || this.roles.indexOf("销售助理岗")!=-1){
             return true
         }
        if( this.roles.indexOf(row.description)!=-1 ){
          if( row.description === '客户经理' && this.projectStatus >=5 && this.projectStatus!=18){
            return false
          }
          return true
        }
        if(row.description === '客户经理') {
           if(this.roles.indexOf("审查岗")!=-1){
             return true
           }
           if(this.roles.indexOf("审批岗")!=-1){
             return true
           }
           if(this.roles.indexOf("尽职调查岗")!=-1){
             return true
           }
           if(this.roles.indexOf("业务负责人")!=-1){
             return true
           }
        }
        if( row.description === '待公证' && this.roles.indexOf("办押岗")!=-1) {
            return true
        }
      },
      handleFileType(row){
        if( row.fileTypeName.indexOf("*") !=-1 ){
          return true
        }
        return false
      },
     getFileList() {
       this.listLoading = true
      listFileByProjecId({projectId:this.defaultProjectId,descriptions: this.descriptions})
        .then(response => {
           this.tableData = []
           var data = response.data
           console.log(data)
           for( let i=0; i<data.length;i++){
              this.tableData.push({
                  id: data[i].id,
                  fileTypeName: data[i].fileTypeName,
                  fileType: data[i].fileType,
                  fileNum: data[i].fileIdList.length,
                  createTime: data[i].createTime,
                  thirdName: data[i].thirdName,
                  bankNo: data[i].bankNo,
                  openBank: data[i].openBank,
                  description:data[i].description,
                  position:data[i].position,
                  createName:data[i].createName,
                  fileUrlList: data[i].fileUrlList,
                  fileIdList: data[i].fileIdList
              })
           }
            this.listLoading = false
        })
        .catch(() => {
          this.tableData = []
           this.listLoading = false
        })
    },
     taskSupplementStatus() {
      taskSupplementStatus({projectId:this.projectId,taskId: this.taskId})
        .then(response => {
          if( response.data != undefined ) {
            console.log(response.data)
             if( this.projectStatus == 18 && response.data >=20){
              this.descriptions.push("尽职调查岗")
            }
            if( this.projectStatus == 18 && response.data >=26){
              this.descriptions.push("尽职调查岗")
              this.descriptions.push("待公证")
            }
            if( this.projectStatus == 18 && response.data >=27){
              this.descriptions.push("办押岗")
            }
            this.getFileList()

          }
        })
        .catch(() => {
        })
    },
    getUploadName(fileType){
      return fileType==22 || fileType == 23 ? "视频" : fileType == 24 ? "录音" : "文件"
    },
    resetForm() {
      this.dataForm = {
        fileTypeName: undefined,
        fileNum: undefined,
        createTime: undefined,
        description:undefined,
        createName:undefined,
        picUrl: undefined

      }
    },
    handleCreate() {
      this.resetForm()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true

      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    uploadPicUrl: function(response) {
      this.dataForm.picUrl = response.data.fileUrl
      this.dataForm.fileId = response.data.id
      // console.log(this.dataForm)
    },
    handleUploadError(res){
       this.$message({
        type: 'error',
        message: '上传文件失败'
      })
    },
    handleBeforeUpload(file){
      console.log(file)
      let beforeArrFlag = true
      this.beforeArr.forEach((item,index)=>{
        if( item.uid!=undefined && item.uid == file.uid) {
          beforeArrFlag = false
        }
      })
      if( beforeArrFlag ) {
      this.beforeArr.push(file)
      this.dataForm.fileUrlList.push(file)
      this.dataForm.fileIdList.push(file)
      }
    },
    handleGalleryUrl(response, file, fileList) {
      try{
      //  console.log(fileList)
       if(this.dataForm.fileUrlList === undefined){
        this.dataForm.fileUrlList = []
        this.dataForm.fileIdList = []
      }
      console.log(this.beforeArr)
      console.log(this.dataForm.fileUrlList)
      console.log("删除前")
      if (response.code === 20000) {
        for( let i=0 ; i< this.beforeArr.length; i++){
          if( this.beforeArr[i].uid == file.uid) {
            this.dataForm.fileUrlList.splice(i,1,{id:response.data.id,fileUrl:response.data.fileUrl,fileName:response.data.fileName})
            this.dataForm.fileIdList.splice(i,1,{fileId:response.data.id,flag:false})
          }
        }
        
      console.log(this.dataForm.fileUrlList)
      console.log("删除后")
      }
      }catch(error){
        this.$message.error(error)
      }finally{
      }
    },
    handleRemove: function(file, fileList) {
      try{
      console.log(this.dataForm.fileUrlList)
      for (var i = 0; i < this.dataForm.fileUrlList.length; i++) {
        // 这里存在两种情况
        // 1. 如果所删除图片是刚刚上传的图片，那么图片地址是file.response.data.url
        //    此时的file.url虽然存在，但是是本机地址，而不是远程地址。
        // 2. 如果所删除图片是后台返回的已有图片，那么图片地址是file.url
        var url
        if (file.response === undefined) {
          url = file.url
        } else {
          url = file.response.data.fileUrl
        }

        if (this.dataForm.fileUrlList[i].fileUrl === url) {
          deleteProjectFile({fileId:this.dataForm.fileUrlList[i].id,fileType:this.dataForm.fileType,projectId:this.defaultProjectId})
            .then(() => {

            })
            .catch(response => {
            })
          this.dataForm.fileUrlList.splice(i, 1)
          this.dataForm.fileIdList.splice(i, 1)
          this.beforeArr.splice(i, 1)
        }
      }
      console.log(this.dataForm.fileUrlList)
      }catch(error){
        this.$message.error(error)
      }finally{
        
      }
    },
    handleUploadLimit(){
        this.$message.error("仅可以上传20个文件");
    },
    handlePictureCardPreview(file){
      console.log(file)
      if( file.response!=undefined){
        this.dialogImageUrl = file.response.data.fileUrl
      }else{
        this.dialogImageUrl = file.fileUrl
      }
      this.dialogFormVisiblePic = true
    },
    backStep(){
      this.$emit("stepChanged",4)
    },
    createData() {
      this.$emit("stepChanged",6)
    },
    uploadFile(row) {
      console.log(row)
      this.dataForm = Object.assign({}, row)
      // this.dataForm.picUrl = undefined
      this.beforeArr = []
      if( this.dataForm.fileUrlList!=undefined && this.dataForm.fileUrlList.length>0){
        this.beforeArr = Object.assign([],this.dataForm.fileUrlList)
      }
      if( this.dataForm.fileUrlList == undefined ) {
        this.dataForm.fileUrlList = []
        this.dataForm.fileIdList = []
      }
      this.dialogStatusTitle = row.fileTypeName
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
       this.galleryFileList = []
        if( this.dataForm.fileIdList!=undefined && this.dataForm.fileIdList.length>0){
           for (var i = 0; i < this.dataForm.fileUrlList.length; i++) {
          this.galleryFileList.push({
            name: this.dataForm.fileUrlList[i].fileName,
            url: this.dataForm.fileUrlList[i].fileUrl
          })
        }
      }
    },
    lookFile(row) {
      console.log(row)
      this.dataForm = Object.assign({}, row)
      // this.dataForm.picUrl = undefined
      //  this.galleryFileList = []
        if( this.dataForm.fileIdList!=undefined && this.dataForm.fileIdList.length>0){
           for (var i = 0; i < this.dataForm.fileUrlList.length; i++) {
          // this.galleryFileList.push({
          //   url: this.dataForm.fileUrlList[i].fileUrl
          // })
          if( this.dataForm.fileUrlList[i].fileName.indexOf("pdf")==-1){
          this.previewPicUrlList.push(this.dataForm.fileUrlList[i].fileUrl)
        }
        }
      }

      // this.picUrlList = row.fileUrlList
      this.dialogStatusPic = row.fileTypeName
      this.dialogFormVisibleDetail = true
    },
    updateData() {
      console.log(this.dataForm)
      let flag = false
      if( this.dataForm.fileIdList == undefined || this.dataForm.length==0){
        flag = true
      }else{
      this.dataForm.fileIdList.forEach((item,index)=>{
        if( item.fileId==undefined) {
          flag = true
        }
      })
      }
      if( flag ) {
        this.$message.error("请稍等，您选择的文件还没有上传成功哦")
        return false
      }
      this.dataForm.projectId = this.defaultProjectId
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          createProjectFile(this.dataForm)
            .then(() => {
              this.listLoading = true
              this.getFileList()
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '保存成功'
              })
            })
            .catch(response => {
            })
        }
      })
    },
    createDataFile() {
      this.dataForm.projectId = this.defaultProjectId
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          createProjectFile(this.dataForm)
            .then(() => {
              this.listLoading = true
              this.getFileList()
              this.dialogFormVisibleDetail = false
              this.$notify.success({
                title: '成功',
                message: '保存成功'
              })
            })
            .catch(response => {
            })
        }
      })
    },
    exportData() {
          let timer = null;
          let _this = this;
          let i= 0;
        this.loading = true
        const loading = this.$loading({
          text:'下载中，请耐心等候...'
        })
        // window.clearInterval(timer)
        // timer = setInterval(() => {
        //   if(i < 99) {
        //     i += 1
        //     _this.percentage = i
        //   }else{
        //     window.clearInterval(timer)
        //     timer = null
        //   }
        // },300 )
        
        exportFile({projectId: this.projectId,descriptions: this.descriptions}, res => {
          // console.log(res,'resssss====>')
            loading.close();
            _this.dialogVisible = true
            let loaded = res.loaded,
              total = res.total;
            _this.$nextTick(() => {
              _this.percentage = parseInt((loaded / total) * 100);
            });
          })
            .then((res) => {
                // _this.percentage = 100
                // window.clearInterval(timer)
              setTimeout(() => {
                  _this.percentage = undefined
                  _this.$notify.success({
                  title: '成功',
                  message: '批量下载成功'
                })
                const content = res
                const blob = new Blob([content],{ type: 'application/zip' })
                const fileName = this.realName+'附件.zip'
                if ('download' in document.createElement('a')) { // 非IE下载
                  const elink = document.createElement('a')
                  elink.download = fileName
                  elink.style.display = 'none'
                  elink.href = URL.createObjectURL(blob)
                  document.body.appendChild(elink)
                  elink.click()
                  URL.revokeObjectURL(elink.href) // 释放URL 对象
                  document.body.removeChild(elink)
                } else { // IE10+下载
                  navigator.msSaveBlob(blob,fileName)
                }
                _this.loading = false
                _this.dialogVisible = false;
                },1000)
              
              
            })
            .catch(response => {
              console.log(response)
              setTimeout(() => {
                 this.loading = false
                _this.dialogVisible = false;
                  _this.percentage = undefined
                window.clearInterval(timer)
                this.$notify.error({
                  title: '失败',
                  message: response.data.message
                })
              },1000)
            })
    },
  }
}
</script>
